'use strict';
var even_group_calculate_average = function(collection){
    let temp2=[];
    let temp=[];
    let sum=0;
    let result=[];
    let temp1=[];
    let end=[];
    for(let i=1;i<collection.length;i=i+2)
        {
            temp2.push(collection[i]);
        }
    for(let i=0;i<temp2.length;i++)
        {
            if(temp2[i]%2==0)
            temp.push(temp2[i]);
        }
    if(temp.length==0)
        {
            end=[0];

        }
    function sortNumber(a,b)
    {
        return a-b;
    }
    temp.sort(sortNumber);
    for(let i=0;i<temp.length;i++)
        {
            temp[i]=String(temp[i]);
        }
    for(let i=0;i<temp.length;)
        {
            sum=0;
            temp1=[];
            for(let j=0;j<temp.length;j++)
                {
                    if(temp[i].length==temp[j].length)
                        {
                            sum+=1;
                            temp1.push(temp[j]);
                        }
                }
            result.push(temp1);
            i+=sum;
        }
    for(let i=0;i<result.length;i++)
        {
            let sum=0;
            for(let j=0;j<result[i].length;j++)
                {
                    result[i][j]=parseInt(result[i][j]);
                    sum+=result[i][j];
                }
            let average=sum/(result[i].length);
            end.push(average);
        }
    return end;
};
module.exports = even_group_calculate_average;
